<!DOCTYPE html>
<html lang="cn">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <link rel="stylesheet" href="./css.css">
  </head>
  <body>
    <div class="box">
      <h1>京东秒杀</h1>
      <p>10:00点场 距结束</p>
      <div class="time">
        <span class="h">10</span>
        &nbsp;:&nbsp;
        <span class="m">20</span>
        &nbsp;:&nbsp;
        <span class="s">30</span>
      </div>
    </div>
    <script>
        var setTime = +new Date('2021-6-30 10:00:00');
        // console.log(setTime);
        var hour = document.querySelector('.h');
        var minute = document.querySelector('.m');
        var second = document.querySelector('.s');
        countDown();
        function countDown() {
            var nowTime = +new Date();
            var diff = (setTime-nowTime)/1000;
            var h = parseInt(diff/60/60%24);
            h = h<10?'0'+h:h;
            hour.innerHTML = h;
            var m = parseInt(diff/60%60);
            m = m<10?'0'+m:m;
            minute.innerHTML = m;
            var s = parseInt(diff%60);
            s = s<10?'0'+s:s;
            second.innerHTML = s;
        }
        setInterval(() => {
            countDown();
        }, 1000);
    </script>
  </body>
</html>
